package com.battle.service.controller.web;

import com.battle.pojo.param.examStudy.*;
import com.battle.pojo.vo.examStudy.*;
import com.battle.pojo.vo.examStudyDetails.GetExamStudyDetailsVo;
import com.battle.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.util.List;

/**
 * web/用户考试管理
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/examStudy/web")
public class ExamStudyWebController {

    private final ExamStudyService service;

    public ExamStudyWebController(ExamStudyService service) {
        this.service = service;
    }


    /**
     * 开始测验
     *
     * @param param
     * @return
     */
    @PostMapping("/createExamStudy")
    public ApiResult<Long> createExamStudy(@RequestBody @Valid CreateExamStudyParam param) {
        return ApiResult.ok(service.createExamStudy(param));
    }


    /**
     * 回答题目
     *
     * @param param
     */
    @PutMapping("/editExamStudy")
    public ApiResult editExamStudy(@RequestBody @Valid EditExamStudyParam param) {
        service.editExamStudy(param);
        return ApiResult.ok();
    }


    /**
     * 获取用户考试详情
     *
     * @param examStudyId
     * @return
     */
    @GetMapping("/getExamStudy")
    public ApiResult<GetExamStudyVo> getExamStudy(@RequestParam("examStudyId") Long examStudyId) {
        GetExamStudyVo vo = service.getExamStudy(examStudyId);
        return ApiResult.ok(vo);
    }

    /**
     * 根据id获取考试题目详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getExamStudyDetails")
    public ApiResult<GetExamStudyDetailsVo> getExamStudyDetails(@RequestParam("id") Long id) {
        GetExamStudyDetailsVo vo = service.getExamStudyDetails(id);
        return ApiResult.ok(vo);
    }

    /**
     * 根据试卷id和用户id获取试卷详情
     * @param examId
     * @param userId
     * @return
     */
    @GetMapping("/getExamDetails")
    public ApiResult<GetExamDetailsVo> getExamDetails(@RequestParam("examId") Long examId,@RequestParam("userId") Long userId) {
        GetExamDetailsVo vo = service.getExamDetails(examId, userId);
        return ApiResult.ok(vo);
    }

    /**
     * 获取用户考试管理列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getExamStudyList")
    public ApiResult<PageResult<GetExamStudyListVo>> getExamStudyList(@RequestBody GetExamStudyListParam param) {
        PageResult<GetExamStudyListVo> result = service.getExamStudyList(param);
        return ApiResult.ok(result);
    }

}

